" 语法高亮
syntax on
" required
filetype off
filetype plugin indent on
" 设置代码折叠方式
set foldmethod=indent
set nofoldenable
" 设置不兼容老的vi格式
set nocompatible   " be iMproved, required
" 粘贴行数限制,不能在nocompatible之前
set viminfo='1000,<500
" set spell
" set mouse=a
" 设置退格键
set backspace=2
" VIM内部编码
set encoding=utf-8
" 默认文件编码
set fileencoding=utf-8
" 支持的文件编码
set fileencodings=utf-8,euc-cn,cp939,latin1
" 显示行号
set number
" 显示相对行号
set relativenumber
" 设置忽略大小写
set ic
" 设置高亮搜索
set hlsearch
" 在搜索时，输入的词句的逐字符高亮
set incsearch
" 显示状态栏
set laststatus=2
" 命令行补全
set wildmode=longest:full,full
set wildmenu
" 按C语言格式缩进
set cindent
" 设置Tab长度为4格
set tabstop=4
" 设置自动缩进长度为4格
set shiftwidth=4
" 继承前一行的缩进方式，特别适用于多行注释
set autoindent
" 用space替代tab的输入
set expandtab
" 显示括号匹配
set showmatch
" 括号匹配显示时间为1(单位是十分之一秒)
set matchtime=1
" 显示行尾空格
set list
set listchars=tab:>-,trail:-
" 显示90列参考线
set colorcolumn=90
" 上下移动光标时，光标上方或下方至少保留的显示行数
set scrolloff=10

" 状态栏
set statusline=
set statusline+=%<%{getcwd()}\ %f                  "File+path
set statusline+=%m%r%h                             "Modified? Readonly? Help?
set statusline+=[%{&ff}]                           "FileFormat (dos/unix..)
set statusline+=[%{''.(&fenc!=''?&fenc:&enc).''}]  "Encoding
set statusline+=%{FugitiveStatusline()}            "Git branch
set statusline+=%=%l/%L,%c%V                       "Row,Column
set laststatus=2

:let mapleader ="-"
"主题
"other: gruvbox
"TODO colors/industry.vim文件中添加下面配色
"hi PMenu ctermfg=0 ctermbg=242 guifg=black guibg=darkgrey
"hi PMenuSel ctermfg=242 ctermbg=8 guifg=darkgrey guibg=black
"~/.bashrc添加下面内容， 开启终端256色 ，source ~/.bashrc
"if [ "$TERM"=="xterm" ]; then
"    export TERM=xterm-256color
"fi
colorscheme industry
if &diff
    colorscheme pablo
endif

"set background=dark
"highlight Normal guibg=NONE ctermbg=None
"highlight PMenu ctermfg=0 ctermbg=242 guifg=black guibg=darkgrey
"highlight PMenuSel ctermfg=242 ctermbg=8 guifg=darkgrey guibg=black
"主题高亮设置
hi ColorColumn ctermbg=darkgrey

"全模式按键映射
map <F1> <plug>NERDTreeTabsToggle<CR>
map <F3> <leader>bt
map <F9> :TagbarToggle<CR>
"正常模式下按键映射
": nnoremap<c-[><<
:nnoremap <c-]> >>
:nnoremap <c-u> gUw
:nnoremap <c-h> :Far 
:nnoremap <space> viw
:nnoremap <c-space> viW
:nnoremap <leader>' viw<esc>a'<esc>hbi'<esc>lel
:nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
:nnoremap <leader>[ viw<esc>a]<esc>hbi[<esc>lel
:nnoremap <leader>( viw<esc>a)<esc>hbi(<esc>lel
:nnoremap <leader>{ viw<esc>a}<esc>hbi{<esc>lel
"可视模式下按键映射
:vnoremap <leader>' s''<esc>hp
:vnoremap <leader>" s""<esc>hp
:vnoremap <leader>[ s[]<esc>hp
:vnoremap <leader>( s()<esc>hp
:vnoremap <leader>{ s{}<esc>hp
"插入模式下按键映射
:inoremap <c-d> <esc>ddi
:inoremap <c-u> <esc>gUwi
:iabbrev @@ 1792520880@qq.com
:iabbrev ture true
": autocmd FileType c++ nnoremap -/ I//<esc>
": autocmd FileType python nnoremap -/ I#<esc>
"定位到上次打开位置
:autocmd BufReadPost *
            \ if line("'\"")>0 && line("'\"") <= line("$")|
            \ exe "normal! g'\"" |
            \ endif


"插件
"Install vim-plug
"curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
"https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
call plug#begin('~/.vim/plugged')
"Plugin 'VundleVim/Vundle.vim'
"Plugin 'morhetz/gruvbox'
Plug 'git@gitee.com:XYLongzzZ/far.vim.git'
Plug 'git@gitee.com:XYLongzzZ/vim-json.git'
Plug 'git@gitee.com:XYLongzzZ/vim-autoformat.git'
Plug 'git@gitee.com:XYLongzzZ/YouCompleteMe.git'
"Plug 'git@gitee.com:XYLongzzZ/coc.nvim.git', {'branch': 'release'}      "TODO: 安装nodejs: curl -sL install-node.now.sh/lts | bash
Plug 'git@gitee.com:XYLongzzZ/DoxygenToolkit.vim.git'       " 代码格式化
Plug 'git@gitee.com:XYLongzzZ/vim-headerguard.git'          " 头文件宏定义
Plug 'git@gitee.com:XYLongzzZ/vim-abolish.git'              " 替换扩展
Plug 'git@gitee.com:XYLongzzZ/nerdtree.git'                 " 文件浏览插件
Plug 'git@gitee.com:XYLongzzZ/nerdtree-git-plugin.git'      " 文件浏览显示git变更状态.
Plug 'git@gitee.com:XYLongzzZ/vim-nerdtree-tabs.git'        " 共享NERDTree
Plug 'git@gitee.com:XYLongzzZ/vim-fugitive.git'             " vim中进行git操作
Plug 'git@gitee.com:XYLongzzZ/LeaderF.git'                  " 文件或内容搜索
Plug 'git@gitee.com:XYLongzzZ/tagbar.git'                   " 侧视图文件的类、结构体、函数、变量等
Plug 'git@gitee.com:XYLongzzZ/vim-gitgutter.git'            " git 侧边栏插件
Plug 'git@gitee.com:XYLongzzZ/nerdcommenter.git'            " 注释
Plug 'git@gitee.com:XYLongzzZ/vim-snippets.git'             " 代码不全，与ultisnips结合使用
Plug 'git@gitee.com:XYLongzzZ/ultisnips.git'
Plug 'git@gitee.com:XYLongzzZ/vim-rainbow.git'              " 多重色彩括号
Plug 'git@gitee.com:XYLongzzZ/auto-pairs.git'               " 自动括号
Plug 'git@gitee.com:XYLongzzZ/vim-signature.git'            " 书签功能
"Plug 'git@gitee.com:XYLongzzZ/bufexplorer.git'              " 多文件切换,LeaderF已实现
"All of your Plugins must be added before the following line
call plug#end()

" To ignore plugin indent changes, instead use:
"filetype plugin on
"Brief help
": PluginList       - lists configured plugins
": PluginInstall    - installs plugins; append `!` to update or just: PluginUpdate
": PluginSearch foo - searches for foo; append `!` to refresh local cache
": PluginClean      - confirms removal of unused plugins; append `!`  to auto-approve removal
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line


" coc配置
let g:coc_disable_startup_warning = 1

" YouCompleteMe配置
set completeopt=menu,menuone
let g:ycm_add_preview_to_completeopt = 0
"let g:ycm_show_diagnostics_ui = 0
let g:ycm_server_log_level = 'debug'
let g:ycm_confirm_extra_conf = 0
let g:ycm_min_num_identifier_candidate_chars = 2
let g:ycm_collect_identifiers_from_comments_and_strings = 1
let g:ycm_complete_in_strings = 1
let g:ycm_error_symbol = '>>'
let g:ycm_warning_symbol = '>*'
let g:ycm_key_invoke_completion = '<c-z>'
let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/.ycm_extra_conf.py'
let g:ycm_semantic_triggers = {
            \ 'c,cpp,python,java,go,erlang,perl': ['re! \w{2}'],
            \ 'cs,lua,javascript': ['re! \w{2}'],
            \ }
let g:ycm_filetype_whitelist = {
            \ "c":1,
            \ "cpp":1,
            \ "python":1,
            \ "javascript":1,
            \ "objc":1,
            \ "sh":1,
            \ "zsh":1,
            \ "zimbu":1,
            \ "vim":1,
            \ }

vnoremap <F2> :YcmCompleter RefactorRename
nnoremap <F2> :YcmCompleter RefactorRename
nnoremap <F8> :YcmCompleter GoToReferences<CR>
nnoremap <F10> :YcmCompleter GoToDeclaration<CR>
nnoremap <F12> :YcmCompleter GoToDefinition<CR>
nnoremap <F6> :YcmCompleter GoToType<CR>
nnoremap <F7> :YcmCompleter GoToSymbol
nmap     <F4> :YcmDiags<CR>

" ctags配置
" set tags+=~/. vim/tags/cpp
"map <F12>: !ctags -R --sort= yes --c++-kinds=+p --fields=+iaS --extra=+q .<CR>
"let OmniCpp_NamespaceSearch =1
"let OmniCpp_GlobalScopeSearch =1
"let OmniCpp_ShowAccess =1
"let OmniCpp_ShowPrototypeInAbbr =1 " show function parameters
"let OmniCpp_MayCompleteDot =1 " autocomplete after
"let OmniCpp_MayCompleteArrow=1 " autocomplete after->
"let OmniCpp_MayCompleteScope=1 " autocomplete after ::
"let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]

" DoxygenToolkit.vim插件参数
let g:DoxygenToolkit_authorName="zl"

" HeaderGuard插件参数
function! g:HeaderguardName()
    return "" . toupper(expand('%:t:gs/[^0-9a-zA-Z_]/_/g')) . "_"
endfunction

" NERDTree配置
let NERDTreeShowHidden=1
let NERDTreeAutoCenter=1
let NERDTreeCascadeSingleChildDir=0
let NERDTreeChDirMode=2
let g:nerdtree_tabs_open_on_console_startup=0
let g:nerdtree_tabs_autoclose=1
let g:NERDTreeGitStatusShowIgnored=1
let g:NERDTreeGitStatusIndicatorMapCustom = {
            \ 'Modified'  :'✹',
            \ 'Staged'    :'✚',
            \ 'Untracked' :'✭',
            \ 'Renamed'   :'➜',
            \ 'Unmerged'  :'═',
            \ 'Deleted'   :'✖',
            \ 'Dirty'     :'✗',
            \ 'Ignored'   :'☒',
            \ 'Clean'     :'✔︎',
            \ 'Unknown'   :'?',
            \ }
let g:NERDTreeGitStatusGitBinPath='/usr/bin/git'

" Leaderf
"let g:Lf_PreviewInPopup = 1
let g:Lf_ShortcutB = '<C-B>'
let g:Lf_ShortcutF = '<C-P>'
let g:Lf_WorkingDirectoryMode = 'Ac'
let g:Lf_RootMarkers = [ '.git','.svn']
let g:Lf_CommandMap = {'<C-K>':['<up>'],'<C-J>':['<down>'],'<C-R>':['<C-E>']}
:nnoremap <C-G> :Leaderf rg<CR>
:nnoremap <C-F> :Leaderf function<CR>

"UltiSnips
"let g:UltiSnipsExpandTrigger="<tab>"
"let g:UltiSnipsJumpForwardTrigger="<c-b>"
"let g:UltiSnipsJumpBackwardTrigger="<c-z>"
"let g:UltiSnipsEditSplit="vertical"

function! g:UltiSnips_Complete()
    call UltiSnips#ExpandSnippet()
    if g:ulti_expand_res ==0
        if pumvisible()
            return "\<C-n>"
        else
            call UltiSnips#JumpForwards()
            if g:ulti_jump_forwards_res == 0
                return "\<TAB>"
            endif
        endif
    endif
    return ""
endfunction

function! g:UltiSnips_Reverse()
    call UltiSnips#JumpBackwards()
    if g:ulti_jump_backwards_res == 0
        return "\<C-P>"
    endif
    return ""
endfunction


if !exists("g:UltiSnipsJumpForwardTrigger")
    let g:UltiSnipsJumpForwardTrigger = "<tab>"
endif
if !exists("g:UltiSnipsJumpBackwardTrigger")
    let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
endif

au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger       . " <C-R>=g:UltiSnips_Complete()<cr>"
au InsertEnter * exec "inoremap <silent> " . g:UltiSnipsJumpBackwardTrigger . " <C-R>=g:UltiSnips_Reverse()<cr>"

" Rainbow
let g:rainbow_active = 1

let g:rainbow_load_separately = [
            \ [ '*' , [['(', ')'], ['\[', '\]'], ['{', '}']] ],
            \ [ '*.tex' , [['(', ')'], ['\[', '\]']] ],
            \ [ '*.cpp' , [['(', ')'], ['\[', '\]'], ['{', '}']] ],
            \ [ '*.{html,htm}' , [['(', ')'], ['\[', '\]'], ['{', '}'], ['<\a[^>]*>', '</[^>]*>']] ],
            \ ]

let g:rainbow_guifgs = ['RoyalBlue3', 'DarkOrange3', 'DarkOrchid3', 'FireBrick']
let g:rainbow_ctermfgs = ['lightblue', 'lightgreen', 'yellow', 'red', 'magenta']
